package function;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnBook implements IFunction{
    public void act(BookList bookList){
        System.out.println("归还书籍:");
        Scanner s = new Scanner(System.in);
        System.out.println("请输入要归还书籍的名字：");
        String bookName = s.nextLine();
        int currentSize = bookList.getBookNum();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(bookName.equals(book.getBookName())){
                if(book.isState() == true){
                    book.setState(false);
                    System.out.println("归还成功");
                    return;
                }else{
                    System.out.println("该书未借出，无需归还");
                }
            }
        }
        System.out.println("没有这本书");
    }
}
